<?php
/**
 * Zend Framework Contribution
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Mwb
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    1.0 View.php 23 mai 2012 Sergio DE VASCONCELOS
 */

//require_once('Zend/Mwb/Dom/Parser/View.php');
class Zend_Mwb_Document_Adapter_DOMDocument_View
{
	protected $node;// $this->node->getDom()->getParent()->getDom();
	protected $parent;
	protected $xpath;
	
	public function __construct($node, $parent=null) {
		$this->node = $node;
		$this->parent = $parent;
		$this->xpath = new DOMXPath($this->node->ownerDocument);
	}
	
    /**
     * @return Array<String>
     */
    public function getColumns()
    {
    	$element = $this->xpath->query("value[@key='columns']", $this->node)->item(0);
    	if (isset($element)) {
        	// @TODO foreach implementation
    	} else {
        	require_once 'Zend/Mwb/Exception.php';
        	throw new Zend_Mwb_Exception('Dom_Exception_Null($this->node)');
        }
    }

    /**
     * @param Array<String>
     * @return Db_Mysql_View
     */
    public function setColumns(String $columns)
    {
        // @TODO implementation
    	return $this;
    }

    /**
     * @return String
     */
    public function getName()
    {
    	$element = $this->xpath->query("value[@key='name']", $this->node)->item(0);
    	if (isset($element)) {
        	return $element->textContent;
        } else {
        	require_once 'Zend/Mwb/Exception.php';
        	throw new Zend_Mwb_Exception('Dom_Exception_Null($this->node)');
        }
    }

    /**
     * @param String
     * @return Db_Mysql_View
     */
    public function setName(String $name)
    {
    	// @TODO implementation write xml
        return $this;
    }

    /**
     * @return String
     */
    public function getSqlDefinition()
    {
    	$element = $this->xpath->query("value[@key='sqlDefinition']", $this->node)->item(0);
    	
    	if (isset($element)) {
        	return $element->textContent;
        } else {
        	require_once 'Zend/Mwb/Exception.php';
        	throw new Zend_Mwb_Exception('Dom_Exception_Null($this->node)');
        }
    }

    /**
     * @param String
     * @return Db_Mysql_View
     */
    public function setSqlDefinition(String $sqlDefinition)
    {
        // @TODO
        
        return $this;
    }

    /**
     * @return String
     */
    public function getComment()
    {
    	$element = $this->xpath->query("value[@key='comment']", $this->node)->item(0);
    	if (isset($element)) {
        	return $element->textContent;
        } else {
        	require_once 'Zend/Mwb/Exception.php';
        	throw new Zend_Mwb_Exception('Dom_Exception_Null($this->node)');
        }
    }

    /**
     * @param String
     * @return Db_Mysql_View
     */
    public function setComment(String $comment)
    {
        
        return $this;
    }

}

require_once('Zend/Mwb/Dom/Abstract.php');
/**
 * MySQL Workbench document
 *
 * @category   Zend
 * @package    Zend_Mwb
 */
class Zend_Mwb_Dom_View extends Zend_Mwb_Dom_Abstract // Zend_Mwb_Dom_Abstract_Object
{

    /**
     * @var Array<String>
     */
    protected $columns = null;

    /**
     * @var String
     */
    protected $isReadOnly = null;

    /**
     * @var String
     */
    protected $name = null;

    /**
     * @var String
     */
    protected $withCheckCondition = null;

    /**
     * @var String
     */
    protected $oldModelSqlDefinition = null;

    /**
     * @var String
     */
    protected $oldServerSqlDefinition = null;

    /**
     * @var String
     */
    protected $sqlDefinition = null;

    /**
     * @var String
     */
    protected $commentedOut = null;

    /**
     * @var String
     */
    protected $createDate = null;

    /**
     * @var String
     */
    protected $customData = null;

    /**
     * @var String
     */
    protected $lastChangeDate = null;

    /**
     * @var String
     */
    protected $modelOnly = null;

    /**
     * @var String
     */
    protected $temp_sql = null;

    /**
     * @var String
     */
    protected $comment = null;

    /**
     * @var String
     */
    protected $oldName = null;

    /**
     * @var GrtObject
     */
    protected $owner = null;

    protected $adapter;
    public function getAdapter()
    {
        if(is_null($this->adapter)) {
            $this->adapter = new Zend_Mwb_Document_Adapter_DOMDocument_View($this->node, $this->parent);
        }
        return $this->adapter;
    }

    /**
     * @return Array<String>
     */
    public function getColumns()
    {
        if(is_null($this->columns)) {
            $this->columns = $this->getAdapter()->getColumns();
        }
        return $this->columns;
    }

    /**
     * @param Array<String>
     * @return Db_Mysql_View
     */
    public function setColumns(String $columns)
    {
        $this->columns = $columns;
        $this->getAdapter()->setColumns($columns);
        return $this;
    }

    /**
     * @return String
     */
    public function getIsReadOnly()
    {
        if(is_null($this->isReadOnly)) {
            $this->isReadOnly = $this->getAdapter()->getIsReadOnly();
        }
        return $this->isReadOnly;
    }

    /**
     * @param String
     * @return Db_Mysql_View
     */
    public function setIsReadOnly(String $isReadOnly)
    {
        $this->isReadOnly = $isReadOnly;
        $this->getAdapter()->setIsReadOnly($isReadOnly);
        return $this;
    }

    /**
     * @return String
     */
    public function getName()
    {
        if(is_null($this->name)) {
            $this->name = $this->getAdapter()->getName();
        }
        return $this->name;
    }

    /**
     * @param String
     * @return Db_Mysql_View
     */
    public function setName(String $name)
    {
        $this->name = $name;
        $this->getAdapter()->setName($name);
        return $this;
    }

    /**
     * @return String
     */
    public function getWithCheckCondition()
    {
        if(is_null($this->withCheckCondition)) {
            $this->withCheckCondition = $this->getAdapter()->getWithCheckCondition();
        }
        return $this->withCheckCondition;
    }

    /**
     * @param String
     * @return Db_Mysql_View
     */
    public function setWithCheckCondition(String $withCheckCondition)
    {
        $this->withCheckCondition = $withCheckCondition;
        $this->getAdapter()->setWithCheckCondition($withCheckCondition);
        return $this;
    }

    /**
     * @return String
     */
    public function getOldModelSqlDefinition()
    {
        if(is_null($this->oldModelSqlDefinition)) {
            $this->oldModelSqlDefinition = $this->getAdapter()->getOldModelSqlDefinition();
        }
        return $this->oldModelSqlDefinition;
    }

    /**
     * @param String
     * @return Db_Mysql_View
     */
    public function setOldModelSqlDefinition(String $oldModelSqlDefinition)
    {
        $this->oldModelSqlDefinition = $oldModelSqlDefinition;
        $this->getAdapter()->setOldModelSqlDefinition($oldModelSqlDefinition);
        return $this;
    }

    /**
     * @return String
     */
    public function getOldServerSqlDefinition()
    {
        if(is_null($this->oldServerSqlDefinition)) {
            $this->oldServerSqlDefinition = $this->getAdapter()->getOldServerSqlDefinition();
        }
        return $this->oldServerSqlDefinition;
    }

    /**
     * @param String
     * @return Db_Mysql_View
     */
    public function setOldServerSqlDefinition(String $oldServerSqlDefinition)
    {
        $this->oldServerSqlDefinition = $oldServerSqlDefinition;
        $this->getAdapter()->setOldServerSqlDefinition($oldServerSqlDefinition);
        return $this;
    }

    /**
     * @return String
     */
    public function getSqlDefinition()
    {
        if(is_null($this->sqlDefinition)) {
            $this->sqlDefinition = $this->getAdapter()->getSqlDefinition();
        }
        return $this->sqlDefinition;
    }

    /**
     * @param String
     * @return Db_Mysql_View
     */
    public function setSqlDefinition(String $sqlDefinition)
    {
        $this->sqlDefinition = $sqlDefinition;
        $this->getAdapter()->setSqlDefinition($sqlDefinition);
        return $this;
    }

    /**
     * @return String
     */
    public function getCommentedOut()
    {
        if(is_null($this->commentedOut)) {
            $this->commentedOut = $this->getAdapter()->getCommentedOut();
        }
        return $this->commentedOut;
    }

    /**
     * @param String
     * @return Db_Mysql_View
     */
    public function setCommentedOut(String $commentedOut)
    {
        $this->commentedOut = $commentedOut;
        $this->getAdapter()->setCommentedOut($commentedOut);
        return $this;
    }

    /**
     * @return String
     */
    public function getCreateDate()
    {
        if(is_null($this->createDate)) {
            $this->createDate = $this->getAdapter()->getCreateDate();
        }
        return $this->createDate;
    }

    /**
     * @param String
     * @return Db_Mysql_View
     */
    public function setCreateDate(String $createDate)
    {
        $this->createDate = $createDate;
        $this->getAdapter()->setCreateDate($createDate);
        return $this;
    }

    /**
     * @return String
     */
    public function getCustomData()
    {
        if(is_null($this->customData)) {
            $this->customData = $this->getAdapter()->getCustomData();
        }
        return $this->customData;
    }

    /**
     * @param String
     * @return Db_Mysql_View
     */
    public function setCustomData(String $customData)
    {
        $this->customData = $customData;
        $this->getAdapter()->setCustomData($customData);
        return $this;
    }

    /**
     * @return String
     */
    public function getLastChangeDate()
    {
        if(is_null($this->lastChangeDate)) {
            $this->lastChangeDate = $this->getAdapter()->getLastChangeDate();
        }
        return $this->lastChangeDate;
    }

    /**
     * @param String
     * @return Db_Mysql_View
     */
    public function setLastChangeDate(String $lastChangeDate)
    {
        $this->lastChangeDate = $lastChangeDate;
        $this->getAdapter()->setLastChangeDate($lastChangeDate);
        return $this;
    }

    /**
     * @return String
     */
    public function getModelOnly()
    {
        if(is_null($this->modelOnly)) {
            $this->modelOnly = $this->getAdapter()->getModelOnly();
        }
        return $this->modelOnly;
    }

    /**
     * @param String
     * @return Db_Mysql_View
     */
    public function setModelOnly(String $modelOnly)
    {
        $this->modelOnly = $modelOnly;
        $this->getAdapter()->setModelOnly($modelOnly);
        return $this;
    }

    /**
     * @return String
     */
    public function getTempSql()
    {
        if(is_null($this->temp_sql)) {
            $this->temp_sql = $this->getAdapter()->getTemp_sql();
        }
        return $this->temp_sql;
    }

    /**
     * @param String
     * @return Db_Mysql_View
     */
    public function setTempSql(String $temp_sql)
    {
        $this->temp_sql = $temp_sql;
        $this->getAdapter()->setTempSql($temp_sql);
        return $this;
    }

    /**
     * @return String
     */
    public function getComment()
    {
        if(is_null($this->comment)) {
            $this->comment = $this->getAdapter()->getComment();
        }
        return $this->comment;
    }

    /**
     * @param String
     * @return Db_Mysql_View
     */
    public function setComment(String $comment)
    {
        $this->comment = $comment;
        $this->getAdapter()->setComment($comment);
        return $this;
    }

    /**
     * @return String
     */
    public function getOldName()
    {
        if(is_null($this->oldName)) {
            $this->oldName = $this->getAdapter()->getOldName();
        }
        return $this->oldName;
    }

    /**
     * @param String
     * @return Db_Mysql_View
     */
    public function setOldName(String $oldName)
    {
        $this->oldName = $oldName;
        $this->getAdapter()->setOldName($oldName);
        return $this;
    }

    /**
     * @return GrtObject
     */
    public function getOwner()
    {
        if(is_null($this->owner)) {
            $this->owner = $this->getAdapter()->getOwner();
        }
        return $this->owner;
    }

    /**
     * @param GrtObject
     * @return Db_Mysql_View
     */
    public function setOwner(GrtObject $owner)
    {
        $this->owner = $owner;
        $this->getAdapter()->setOwner($owner);
        return $this;
    }


}
